<?php 
//分页1
function pagination($query_string){
global $posts_per_page, $paged;
$my_query = new WP_Query($query_string ."&posts_per_page=-1");
$total_posts = $my_query->post_count;
if(empty($paged))$paged = 1;
$prev = $paged - 1;							
$next = $paged + 1;	
$range = 6; // 修改数字,可以显示更多的分页链接
$showitems = ($range * 2)+1;
$pages = ceil($total_posts/$posts_per_page);
if(1 != $pages){
	echo "<div class='pagination'>";
	echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? "<a href='".get_pagenum_link(1)."'>最前</a>":"";
	echo ($paged > 1 && $showitems < $pages)? "<a href='".get_pagenum_link($prev)."'>上一页</a>":"";		
	for ($i=1; $i <= $pages; $i++){
	if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
	echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>"; 
	}
	}
	echo ($paged < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($next)."'>下一页</a>" :"";
	echo ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($pages)."'>最后</a>":"";
	echo "</div>\n";
	}
}

function pagenavi() {
 global $wp_query, $wp_rewrite;
 $wp_query->query_vars['page'] > 1 ? $current = $wp_query->query_vars['page'] : $current = 1;
 $pagination = array(
 'base' => @add_query_arg('page','%#%'),
 'format' => '',
 'total' => $wp_query->max_num_pages,
 'current' => $current,
 'show_all' => true,
 'type' => 'plain',
 'prev_next' => true
 );
 if( $wp_rewrite->using_permalinks() )
 $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'page');
 if( !empty($wp_query->query_vars['s']) )
 $pagination['add_args'] = array('s'=>get_query_var('s'));
 echo '<div class="pagenavi" id="pagenavi">'.paginate_links($pagination).'</div>';
 }


function vt_nav(){

global $wp_query, $wp_rewrite;

$wp_query->query_vars['page'] > 1 ? $current = $wp_query->query_vars['page'] : $current = 1;

$pagination = array(

'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'prev_text' => '◀ 上一页',
'next_text' => '下一页  ▶',
'end_size'     => 3,    
'mid_size'     => 3,
'prev_next'    => true,
);


if( $wp_rewrite->using_permalinks() )

$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'page');

if( !empty($wp_query->query_vars['s']) )

$pagination['add_args'] = array('s'=>get_query_var('s'));
echo '<div  class="pagenavi" id="pagenavi">'.paginate_links($pagination).'</div>';

}

?>